<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>1F钢架E化方案 - 后台管理 - 后台首页</title>
  <%@include file="/WEB-INF/common/css.jsp"%>
  
  <%@include file="/WEB-INF/common/topjs.jsp"%>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
  
  <%@include file="/WEB-INF/common/admin/header.jsp"%>
  <%@include file="/WEB-INF/common/admin/menu.jsp"%>
  
  <div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">
    	<h3 class="layui-bg-cyan" style="height: 50px;line-height: 50px;padding-left: 5px">部门列表</h3>
		<hr>
		<div>
			<table  class="layui-table"  id="listshow">
				
			</table>
		</div>
    </div>
  </div>
  
  <%@include file="/WEB-INF/common/admin/footer.jsp"%>
  
</div>
<%@include file="/WEB-INF/common/bottomjs.jsp"%>
<script>
	(function(){
		$.ajax({
			url:"${base}/admin/department/list.api",
	    	type: "post",
	    	headers: Apicheck.getHeaders(),
	    	data: {page: 1,size: 10},
	    	success: function(result){
	    		console.log(result);
	    		var xtable = new XTable();
	    		xtable.setOption({
	    			type: XTable.NORMAL,
	    			head: [{name:"ID"},{name:"部门"},{name:"创建时间"},{name:"最后修改时间"},{name:"操作"}],
	    			buttons:[{
	    				class: "layui-btn",
	    				style: "",
	    				name: "编辑",
	    				click: function(e){
	    					layer.open({
    						   title: '部门编辑'
    						   ,content: '<input type="text" id="updatename" class="layui-input" value="'+e.name+'">'
    						   ,yes: function(index, layero){
    							   $.ajax({
    							    	url:"${base}/admin/department/update",
    							    	type: "post",
    							    	data: {id: e.id, name: $("#updatename").val()},
    							    	success: function(result){
    							    		if(result.code == 1001){
    							    			//layer.msg(result.msg, {icon:6});
    							    			location.reload();
    							    		}else{
    							    			layer.msg(result.msg, {icon:5,anim:6});
    							    		}
    							    	}
    							    });
    						   }
    						});
	    				}
	    			}, {
	    				class: "layui-btn layui-btn-danger",
	    				style: "",
	    				name: "删除",
	    				click: function(e){
	    					layer.open({
    						   title: '部门删除'
    						   ,content: '真要删吗?，千万别手残咯'
    						   ,yes: function(index, layero){
    							   $.ajax({
    							    	url:"${base}/admin/department/delete",
    							    	type: "post",
    							    	data: {id: e.id},
    							    	success: function(result){
    							    		if(result.code == 1001){
    							    			//layer.msg(result.msg, {icon:6});
    							    			location.reload();
    							    		}else{
    							    			layer.msg(result.msg, {icon:5,anim:6});
    							    		}
    							    	}
    							    });
    						   }
    						});
	    				}
	    			}],
	    			data: result.data
	    		});
	    		xtable.show("listshow");
	    	}
		});
	})()
</script>
</body>
</html>